#ifndef STR_H
#define STR_H
#include <deque>
#include <time.h>
#include <stdlib.h>

class str{
private:
    int N;
    double koef;
    double freq;
    std::deque<double> buf;
public:
    str(double freq, int SR, double koef){
        this -> freq = freq;
        this -> N = SR / freq;
        this -> koef = koef;
    }
    void pluck();
    double sample();
};

void str::pluck(){
    double temp;
    for (int i = 0; i < this -> N; ++i){
        temp = (rand() + 17000);
        temp /= 100000;
        if (rand() % 2)
            temp *= -1;
        this -> buf.push_back(temp);
    }
}

double str::sample(){
    double avg = this -> koef * 0.5 * (this -> buf[0] + this -> buf[1]);
    this -> buf.push_back(avg);
    this -> buf.pop_front();
    return avg;
}

#endif // STR_H
